package org.coderfun.boot.web.controller;

import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.coderfun.boot.core.service.UserRoleService;
import org.coderfun.boot.web.model.UserRoleRequestRequest;
import org.coderfun.common.log.LogModuleCode;
import org.coderfun.common.log.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import klg.common.model.JsonData;

/**
 *
 * 
 * Generated by fieldmeta at 2018-10-23T14:08:29+08:00
 *
 */

@Controller("adminUserRoleController")
@RequestMapping("/admin/action/boot/userrole")
public class UserRoleController {
	@Autowired
	UserRoleService userRoleService;

	
	@ResponseBody
	@RequestMapping("/findRoleIdsByUserId")
	@RequiresPermissions("boot:userRole:query")
	public JsonData findRoleIdsByUserId(@RequestParam Long userId) {
		return JsonData.success(userRoleService.findRoleIdsByUserId(userId));
	}

	@Logger(name = "更新用户角色" , moduleCode = LogModuleCode.BOOT)
	@ResponseBody
	@RequestMapping("/updateUserRoles")
	@RequiresPermissions("boot:userRole:update")
	public JsonData updateUserRoles(@RequestBody UserRoleRequestRequest userRoleRequest) {

		userRoleService.updateUserRoles(userRoleRequest.getUserId(), userRoleRequest.getRoleIds());
		return JsonData.success();
	}

}
